package com.cz.nongyetongv5.adapter;

import java.util.List;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cz.nongyetongv5.R;
import com.cz.nongyetongv5.activity.JianGuanDuiXiangActivity;
import com.cz.nongyetongv5.bean.BeiJianDanWei;
import com.cz.nongyetongv5.bean.JianGuanDuiXiangFilter;
import com.cz.nongyetongv5.bean.Town;
import com.cz.nongyetongv5.utils.ConfigUtil;

public class JianGuanDuiXiangListAdapter2 extends BaseAdapter {

	// 上下文对象
	private Context context = null;

	private List datas = null;



	private JianGuanDuiXiangActivity onClickListener = null;

	private JianGuanDuiXiangFilter filter = null;


	private ConfigUtil configUtil = null;

	public   JianGuanDuiXiangListAdapter2(Context context, List datas,
										  JianGuanDuiXiangActivity onClickListener,
										  JianGuanDuiXiangFilter filter) {
		this.context = context;
		this.datas = datas;

		this.onClickListener = onClickListener;
		this.filter = filter;


		configUtil = new ConfigUtil(context.getResources());

	}

	@Override
	public int getCount() {
		return datas == null ? 0 : datas.size();
	}

	@Override
	public Object getItem(int arg0) {
		return datas.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {

		ViewGroup tongXunLuItemLayout = null;

		if (view == null) {
			tongXunLuItemLayout = (ViewGroup) LayoutInflater.from(context)
					.inflate(R.layout.jianguanduixiang_item_layout, null);
		} else {
			tongXunLuItemLayout = (ViewGroup) view;
		}

		ViewGroup llTongXuLuRightLayout = (ViewGroup) tongXunLuItemLayout
				.findViewById(R.id.llTongXuLuRightLayout);

		View ivCall = tongXunLuItemLayout.findViewById(R.id.ivCall);

		View ivMore = tongXunLuItemLayout.findViewById(R.id.ivMore);

		TextView tvTitle = (TextView) tongXunLuItemLayout
				.findViewById(R.id.tvTitle);

		TextView tvJvLi = (TextView) tongXunLuItemLayout
				.findViewById(R.id.tvJvLi);

		Object data = datas.get(position);

		if (data != null && data instanceof BeiJianDanWei) {
			BeiJianDanWei beiJianDanWei = (BeiJianDanWei) data;
			String lab="";
			if(!this.filter.isAll()){
				if(beiJianDanWei.getRegionName()!=null)
					lab="["+beiJianDanWei.getRegionName()+"]";
			}
			tvTitle.setText(lab+beiJianDanWei.getName());
			tvJvLi.setText("");

		} else {
			tvJvLi.setVisibility(View.INVISIBLE);
		}
		if (data != null && data instanceof Town) {

			tvJvLi.setVisibility(View.GONE);

			llTongXuLuRightLayout.setClickable(false);

			ivCall.setVisibility(View.GONE);
			ivMore.setVisibility(View.VISIBLE);

			Town town = (Town) data;



			tvTitle.setText(town.getName() + "\u0020[" + town.getBeijiandanwei() + "]");


		}

		return tongXunLuItemLayout;
	}

	public void setData(List datas) {
		this.datas = datas;
	}

	public void setFilter(JianGuanDuiXiangFilter filter) {
		this.filter = filter;
	}



}
